package com.study.custom.mybatis;

import java.io.InputStream;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/12/23 21:03
 */
public class DefaultSqlSessionFactory implements SqlSessionFactory {

    //SqlMapConfig.xml的字节输入流
    private InputStream is;
    public void setIs(InputStream is) {
        this.is = is;
    }

    public SqlSession openSession() {
        //创建一个DefaultSqlSession
        DefaultSqlSession sqlSession = new DefaultSqlSession();
        //加载解析配置文件
        Configuration cfg = XMLConfigBuilder.loadConfiguration(is);
        sqlSession.setCfg(cfg);

        return sqlSession;
    }
}
